<?php

namespace app\api\controller;

use app\admin\model\tf2020\Teacher;
use app\common\controller\Api;
use think\Db;
use EasyWeChat\Factory;

/**
 * 提分宝典视频
 */
class Tf2020 extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
  
    protected $noNeedRight = ['*'];

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new Teacher();
    }

    /**
     * @ApiTitle    (获取视频信息)
     * @ApiSummary  (select)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/tf2020/select)
     * @ApiParams   (name="year", type="integer", required=true, description="年分")
     * @ApiParams   (name="catid", type="string", required=true, description="CatID科目id")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ()
     * */
    public function select()
    {
        if(!$year = $this->request->request('year'))
        {
            $this->error('请传入年份!');
        }
        if(!$catid = $this->request->request('catid'))
        {
            $this->error('请传入catid!');
        }
        $catid = explode(',',$catid);
        $where['year'] = $year;
        $where['catid'] = ['in',$catid];
        $list = $this->model->where($where)->select();
        $this->success('返回成功', ['total'=>count($list),'list' => $list]);
    }

    /**
     * @ApiTitle    (删除视频信息)
     * @ApiSummary  (select)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/tf2020/del)
     * @ApiParams   (name="year", type="integer", required=true, description="年分")
     * @ApiParams   (name="catid", type="string", required=true, description="CatID科目id")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data.num", type="string", required=true, sample="删除数量")
     * @ApiReturn   ({
    code: 1,
    msg: "返回成功",
    time: "1590475293",
    data: {
    num: 0
    }
    })
     * */
    public function del()
    {
        if(!$year = $this->request->request('year'))
        {
            $this->error('请传入年份!');
        }
        if(!$catid = $this->request->request('catid'))
        {
            $this->error('请传入catid!');
        }
        $catid = explode(',',$catid);
        $where['year'] = $year;
        $where['catid'] = ['in',$catid];
        $num = $this->model->where($where)->delete();
        $this->success('返回成功', ['num' => $num]);
    }
}
